package com.android.fragmentdemo
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.android.fragmentdemo.adapters.RvNestingRvAdapter
import com.hengfoxwolf.commonbase.base.BaseActivity2
import com.android.fragmentdemo.databinding.ActivityDynamicContainer2Binding

class DynamicContainer2Activity :
    BaseActivity2<ActivityDynamicContainer2Binding>(ActivityDynamicContainer2Binding::inflate) {
    override fun init(savedInstanceState: Bundle?) {

        mBinding.dyRootRv.apply {
            layoutManager = LinearLayoutManager(this@DynamicContainer2Activity)
            adapter = RvNestingRvAdapter()
        }

//        if (mBinding.dyRootContainer.shouldAddView()) {
//            addTitleView(resources.getString(R.string.txt_title_view), R.id.title_view_01)
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//            addContentView0()
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//            addTitleView(resources.getString(R.string.txt_color_square), R.id.title_view_02)
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//            addContentView1()
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//
//            addTitleView(resources.getString(R.string.txt_content_square), R.id.title_view_03)
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//            addContentView2()
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//            Log.d(TAG, "title_04:${mBinding.dyRootContainer.shouldAddView()}")
//            addTitleView(resources.getString(R.string.txt_number_content_square), R.id.title_view_04)
//        }
//
//        if (mBinding.dyRootContainer.shouldAddView()) {
//            Log.d(TAG, "content_04:${mBinding.dyRootContainer.shouldAddView()}")
//            addContentView3()
//        }
    }

//    private fun addTitleView(content: String, textViewId: Int) {
//        val titleView = AppCompatTextView(this)
//        titleView.apply {
//            id = textViewId
//            text = content
//            textSize = TypedValue.applyDimension(
//                TypedValue.COMPLEX_UNIT_SP,
//                8F,
//                resources.displayMetrics
//            )
//            setTextColor(resources.getColor(R.color.color_00BFA5))
//        }
//        val layoutParams = MarginLayoutParams(
//            MarginLayoutParams.WRAP_CONTENT,
//            MarginLayoutParams.WRAP_CONTENT
//            //600,
//            //120
//        )
//        layoutParams.topMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        layoutParams.leftMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        //mBinding.dyRootContainer.addView(titleView)
//        mBinding.dyRootContainer.addView(titleView, layoutParams)
//    }
//
//    private fun addContentView0() {
//        val mBodyBinding =
//            DataBindingUtil.inflate<ExpandLayoutBody2Binding>(
//                layoutInflater,
//                R.layout.expand_layout_body2,
//                null,
//                false
//            )
//        val dyAdapter = DynamicItem01Adapter()
//        dyAdapter.itemDataSet = DataFactoryIp.createCharStr(10)
//        mBodyBinding.expandViewRv.apply {
//            layoutManager = LinearLayoutManager(
//                this@DynamicContainer2Activity,
//                LinearLayoutManager.HORIZONTAL,
//                false
//            )
//            adapter = dyAdapter
//            addItemDecoration(
//                Dy01ItemDecoration(
//                    this@DynamicContainer2Activity.resources.getDimension(
//                        R.dimen.dp_10
//                    )
//                )
//            )
//        }
//
//        val layoutParams = LinearLayoutCompat.LayoutParams(
//            LinearLayoutCompat.LayoutParams.MATCH_PARENT,
//            LinearLayoutCompat.LayoutParams.WRAP_CONTENT
//        )
//        layoutParams.leftMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        layoutParams.topMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        mBinding.dyRootContainer.addView(mBodyBinding.root, layoutParams)
//    }
//
//    private fun addContentView1() {
//        val mBodyBinding =
//            DataBindingUtil.inflate<ExpandLayoutBody2Binding>(
//                layoutInflater,
//                R.layout.expand_layout_body2,
//                null,
//                false
//            )
//        val dyAdapter = DynamicItem02Adapter()
//        dyAdapter.itemDataSet = DataFactoryIp.createColorList()
//        mBodyBinding.expandViewRv.apply {
//            layoutManager = GridLayoutManager(
//                this@DynamicContainer2Activity,
//                4
//            )
//            adapter = dyAdapter
//            addItemDecoration(GridItemDecoration(this@DynamicContainer2Activity, 4))
//        }
//
//        val layoutParams = LinearLayoutCompat.LayoutParams(
//            LinearLayoutCompat.LayoutParams.MATCH_PARENT,
//            LinearLayoutCompat.LayoutParams.WRAP_CONTENT
//        )
//        //layoutParams.leftMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        //layoutParams.topMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        mBinding.dyRootContainer.addView(mBodyBinding.root, layoutParams)
//    }
//
//    private fun addContentView2() {
//        val mBodyBinding =
//            DataBindingUtil.inflate<ExpandLayoutBody2Binding>(
//                layoutInflater,
//                R.layout.expand_layout_body2,
//                null,
//                false
//            )
//        val dyAdapter = DynamicItem03Adapter()
//        dyAdapter.itemDataSet = DataFactoryIp.createStrDataSet().subList(0,12)
//        mBodyBinding.expandViewRv.apply {
//            layoutManager = LinearLayoutManager(
//                this@DynamicContainer2Activity,
//            )
//            adapter = dyAdapter
//            addItemDecoration(ListDataItemDecoration(this@DynamicContainer2Activity).apply {
//                setDrawLastLine(false)
//            })
//        }
//
//        val layoutParams = LinearLayoutCompat.LayoutParams(
//            LinearLayoutCompat.LayoutParams.MATCH_PARENT,
//            LinearLayoutCompat.LayoutParams.WRAP_CONTENT
//        )
//        layoutParams.leftMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        layoutParams.rightMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        layoutParams.topMargin = resources.getDimension(R.dimen.dp_10).toInt()
//        mBinding.dyRootContainer.addView(mBodyBinding.root, layoutParams)
//    }
//
//    private fun addContentView3() {
//        val mBodyBinding =
//            DataBindingUtil.inflate<ExpandLayoutBody2Binding>(
//                layoutInflater,
//                R.layout.expand_layout_body2,
//                null,
//                false
//            )
//        val dyAdapter = DynamicItem04Adapter()
//        dyAdapter.itemDataSet = DataFactoryIp.createDataSet()
//        mBodyBinding.expandViewRv.apply {
//            layoutManager = GridLayoutManager(
//                this@DynamicContainer2Activity,
//                3
//            )
//            adapter = dyAdapter
//            addItemDecoration(GridItemDecoration(this@DynamicContainer2Activity, 3).apply {
//                setAddExtraSpace(true)
//            })
//        }
//
//        val layoutParams = LinearLayoutCompat.LayoutParams(
//            LinearLayoutCompat.LayoutParams.MATCH_PARENT,
//            LinearLayoutCompat.LayoutParams.WRAP_CONTENT
//        )
//        mBinding.dyRootContainer.addView(mBodyBinding.root, layoutParams)
//    }

    companion object {
        const val TAG = "DynamicContainer2Activity"
    }
}